package cn.com.czpb.client.module.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.support.annotation.StyleRes;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import com.bumptech.glide.Glide;

import cn.com.czpb.client.R;
import cn.com.czpb.client.custorm.TouchImageView;

/**
 * Created by 猪猪侠 on 2017/11/17.
 */

public class ImgDialog extends Dialog {
    private String imgurl;
    private Activity  activity;
    private TouchImageView imageView;
    private LinearLayout ll_root_id;

    public ImgDialog(@NonNull Context context) {
        super(context);
    }

    public ImgDialog(@NonNull Context context, @StyleRes int themeResId, final String imgurl) {
        super(context, themeResId);
        this.imgurl = imgurl;
        this.activity = (Activity) context;
        View view = LayoutInflater.from(activity).inflate(R.layout.activity_img, null);
        imageView = view.findViewById(R.id.touch_img_id);

        new Handler(Looper.getMainLooper()).post(new Runnable() {
            @Override
            public void run() {
                Glide.with(activity)
                        .load(imgurl)
                        .into(imageView);
            }
        });
//activity.runOnUiThread(new Runnable() {
//    @Override
//    public void run() {
//        Glide.with(activity)
//                .load(imgurl)
//                .into(imageView);
//    }
//});

        ll_root_id = view.findViewById(R.id.ll_root_id);
        ll_root_id.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
        setContentView(view);
    }

}
